package cn.smbms.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StrToDateConverter implements Converter<String, Date> {

    private String datePattern;

    public StrToDateConverter(String datePattern) {
        this.datePattern = datePattern;
    }

    public StrToDateConverter() {
    }

    @Override
    public Date convert(String s) {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(datePattern);
        Date d=null;
        try{
            d=simpleDateFormat.parse(s);
        }catch (Exception e){
            e.printStackTrace();
        }
        return d;
    }
}
